<template>
  <el-drawer
    v-model="drawerVisible"
    :size="650"
    title="高级查询"
    @closed="$emit('closed')"
    append-to-body
  >
    <el-container v-loading="saveLoading">
      <el-main>
        <el-form
          :model="form"
          :rules="rules"
          ref="saveForm"
          label-width="140px"
        >
          <el-form-item label="企业名称" prop="name">
            <el-input
              v-model="form.name"
              placeholder="请输入企业名称"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item label="企业类型" prop="enterpriseType">
            <el-input
              v-model="form.enterpriseType"
              placeholder="请输入企业类型"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item label="企业属地" prop="block">
            <hh-dict
              v-model="form.block"
              dictType="block"
              placeholder="请选择企业属地"
              clearable
              filterable
            ></hh-dict>
          </el-form-item>
          <el-form-item label="法定代表人" prop="legalPerson">
            <el-input
              v-model="form.legalPerson"
              placeholder="请输入法定代表人"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item label="统一社会信用代码" prop="unifiedCode">
            <el-input
              v-model="form.unifiedCode"
              placeholder="请输入统一社会信用代码"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item label="注册资本" prop="regCapital">
            <el-input
              v-model="form.regCapital"
              placeholder="请输入注册资本"
              clearable
            >
              <template #append>万元</template></el-input
            >
          </el-form-item>
          <el-form-item label="注册地址" prop="address">
            <el-input
              v-model="form.address"
              placeholder="请输入注册地址"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item label="联系电话" prop="contactNumber">
            <el-input
              v-model="form.contactNumber"
              placeholder="请输入联系电话"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item label="注册日期范围" prop="regDate">
            <el-date-picker
              v-model="regDateScope"
              type="daterange"
              range-separator="至"
              start-placeholder="最早注册日期"
              end-placeholder="最晚注册日期"
              value-format="YYYY-MM-DD"
              :clearable="true"
            />
          </el-form-item>
          <el-form-item label="所属行业" prop="industry">
            <el-input
              v-model="form.industry"
              placeholder="请输入所属行业"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item label="缴纳社保信息" prop="insrcInfo">
            <hh-dict
              v-model="form.insrcInfo"
              dictType="insrc_contributions"
              placeholder="请选择缴纳社保信息"
              clearable
              filterable
            ></hh-dict>
          </el-form-item>
          <el-form-item label="缴纳人数" prop="personCount">
            <el-input
              v-model="form.personCount"
              placeholder="请输入缴纳人数"
              clearable
            ></el-input>
          </el-form-item>
        </el-form>
      </el-main>
      <el-footer>
        <div class="form-footer">
          <!-- <el-button type="" @click="close">取消</el-button> -->
          <el-button type="" @click="clear">清空查询条件</el-button>
          <el-button type="primary" @click="submit">查询</el-button>
        </div>
      </el-footer>
    </el-container>
  </el-drawer>
</template>

<script>
export default {
  name: "enterprise-filter",
  emits: ["success", "closed"],
  data() {
    return {
      drawerVisible: false,
      form: {
        name: "",
        enterpriseType: "",
        block: "",
        orderNum: null,
        legalPerson: "",
        unifiedCode: "",
        regCapital: "",
        address: "",
        contactNumber: "",
        minRegDate: "",
        maxRegDate: "",
        industry: "",
      },
      rules: {
        // roleName: [{ required: true, message: "请输入企业名称" }],
        personCount: [
          {
            pattern: /^(0|\+?[1-9][0-9]*)$/,
            message: "请输入正确的缴纳人数",
            trigger: "blur",
          },
        ],
      },
      regDateScope: [],
    };
  },
  watch: {
    //日期范围转换
    regDateScope(val) {
      if (val) {
        this.form.minRegDate = val[0];
        this.form.maxRegDate = val[1];
      } else {
        this.form.minRegDate = "";
        this.form.maxRegDate = "";
      }
    },
  },
  mounted() {},
  methods: {
    //打开
    open(search) {
      this.drawerVisible = true;
      Object.assign(this.form, search);
      //日期范围转换
      if (this.form.minRegDate && this.form.maxRegDate) {
        this.regDateScope[0] = this.form.minRegDate;
        this.regDateScope[1] = this.form.maxRegDate;
      }
    },
    //提交
    submit() {
      this.$refs.saveForm.validate(async (valid) => {
        if (valid) {
          this.$emit("onRefresh", this.form);
          this.close();
        }
      });
    },
    //表单注入数据
    clear() {
      let form = {
        name: "",
        enterpriseType: "", //精确
        block: "",
        orderNum: null,
        legalPerson: "",
        unifiedCode: "",
        regCapital: "",
        address: "", //精确
        contactNumber: "",
        regDate: "", //精确
        industry: "", //精确
        minRegDate: "",
        maxRegDate: "",
      };
      this.regDateScope = [];
      Object.assign(this.form, form);
    },
    // 关闭页面
    close() {
      this.$emit("closed");
    },
  },
};
</script>

<style></style>
